<template>
  <div class="xisha_2">
    <div v-if="!inline" class="content_title" style="cursor: pointer" @click="showDialogTech">
      <span class="content_text">细纱</span>
      <img class="content_img" src="@/assets/img/chart/xisha.png" alt="" srcset="" />
    </div>
    <div class="xisha_body">
      <div class="cuxilian"></div>
      <div class="xisha_row2 reserve-row">
        <div
          class="item1"
          v-if="$store.state.workshopNo == 2"
          v-for="(item, index) in xishaData.xishaRow2Data"
          :key="index + 'z'"
        >
          <div v-if="index == 4 || index == 12 || index == 22 || index == 25">
            <div :class="{ dongli3_inline: inline, dongli: !inline }" @click="clickHandleDl('xisha3_' + index)">
              <img :class="{ img: inline }" src="@/assets/img/dongligui.png" alt="" srcset="" />
            </div>
          </div>
          <div @click="clickHandle(item)">
            <xisha :data="item"></xisha>
          </div>
        </div>
        <div
          class="item1"
          v-if="$store.state.workshopNo == 3"
          v-for="(item, index) in xishaData.xishaRow2Data"
          :key="index + 'z'"
        >
          <div v-if="index == 4 || index == 12 || index == 22 || index == 25">
            <div :class="{ dongli3_inline: inline, dongli: !inline }" @click="clickHandleDl('xisha3_' + index)">
              <img :class="{ img: inline }" src="@/assets/img/dongligui.png" alt="" srcset="" />
            </div>
          </div>
          <div @click="clickHandle(item)">
            <xisha :data="item"></xisha>
          </div>
        </div>
        <div
          class="item1"
          v-if="$store.state.workshopNo == 5"
          v-for="(item, index) in xishaData.xishaRow2Data"
          :key="index + 'z'"
        >
          <div v-if="index == 4 || index == 12 || index == 22 || index == 25">
            <div :class="{ dongli3_inline: inline, dongli: !inline }" @click="clickHandleDl('xisha3_' + index)">
              <img :class="{ img: inline }" src="@/assets/img/dongligui.png" alt="" srcset="" />
            </div>
          </div>
          <div @click="clickHandle(item)">
            <xisha :data="item"></xisha>
          </div>
        </div>
        <div
          class="item1"
          v-if="$store.state.workshopNo == 6"
          v-for="(item, index) in xishaData.xishaRow2Data"
          :key="index + 'z'"
        >
          <div v-if="index == 4 || index == 12 || index == 22 || index == 25">
            <div :class="{ dongli3_inline: inline, dongli: !inline }" @click="clickHandleDl('xisha3_' + index)">
              <img :class="{ img: inline }" src="@/assets/img/dongligui.png" alt="" srcset="" />
            </div>
          </div>
          <div @click="clickHandle(item)">
            <xisha :data="item"></xisha>
          </div>
        </div>
      </div>
      <!-- <i class="wall"></i> -->
      <div class="xisha_row3 reserve-row">
        <div
          class="item1"
          v-if="$store.state.workshopNo == 2"
          v-for="(item, index) in xishaData.xishaRow3Data"
          :key="index + 'x'"
        >
          <div v-if="index == 2 || index == 12 || index == 18 || index == 27">
            <div :class="{ dongli4_inline: inline, dongli: !inline }" @click="clickHandleDl('xisha4_' + index)">
              <img :class="{ img: inline }" src="@/assets/img/dongligui.png" alt="" srcset="" />
            </div>
          </div>
          <div @click="clickHandle(item)">
            <xisha :data="item"></xisha>
          </div>
        </div>
        <div
          class="item1"
          v-if="$store.state.workshopNo == 3"
          v-for="(item, index) in xishaData.xishaRow3Data"
          :key="index + 'x'"
        >
          <div v-if="index == 2 || index == 12 || index == 18 || index == 27">
            <div :class="{ dongli4_inline: inline, dongli: !inline }" @click="clickHandleDl('xisha4_' + index)">
              <img :class="{ img: inline }" src="@/assets/img/dongligui.png" alt="" srcset="" />
            </div>
          </div>
          <div @click="clickHandle(item)">
            <xisha :data="item"></xisha>
          </div>
        </div>
        <div
          class="item1"
          v-if="$store.state.workshopNo == 5"
          v-for="(item, index) in xishaData.xishaRow3Data"
          :key="index + 'x'"
        >
          <div v-if="index == 2 || index == 12 || index == 18 || index == 27">
            <div :class="{ dongli4_inline: inline, dongli: !inline }" @click="clickHandleDl('xisha4_' + index)">
              <img :class="{ img: inline }" src="@/assets/img/dongligui.png" alt="" srcset="" />
            </div>
          </div>
          <div @click="clickHandle(item)">
            <xisha :data="item"></xisha>
          </div>
        </div>
        <div
          class="item1"
          v-if="$store.state.workshopNo == 6"
          v-for="(item, index) in xishaData.xishaRow3Data"
          :key="index + 'x'"
        >
          <div v-if="index == 2 || index == 12 || index == 18 || index == 27">
            <div :class="{ dongli4_inline: inline, dongli: !inline }" @click="clickHandleDl('xisha4_' + index)">
              <img :class="{ img: inline }" src="@/assets/img/dongligui.png" alt="" srcset="" />
            </div>
          </div>
          <div @click="clickHandle(item)">
            <xisha :data="item"></xisha>
          </div>
        </div>
      </div>
    </div>
    <xishaDialog :defaultData="data1" v-if="showModal" ref="xishaDialog" />
    <!-- 动力柜弹窗控件 -->
    <dongliDialog v-if="showDongliModal" ref="dongliDialog" />
    <!-- 细纱工艺详情 -->
    <xisha-dialog-tech v-if="techShow" ref="xishaDialogTech"></xisha-dialog-tech>
  </div>
</template>

<script>
import dongliDialog from '@/views/monitorCenter/workChart/components/qcs/dialog/dialog_dongli/index'
import xisha from '@/views/monitorCenter/workChart/components/qcs/xisha'
import xishaDialog from '@/views/monitorCenter/workChart/components/qcs/dialog/dialog_xisha/index'
import COMMON from '@/utils/common'
import dongLiMenu from '@/assets/data/dongli.json'
import dongliItem from '@/assets/data/dongliItem.json'
export default {
  name: 'XiSha',
  props: {
    msg: String,
    // 是否嵌套在弹窗内
    inline: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      loading: true,
      xishaData: {
        // 1-49
        xishaRow2Data: [],
        // 50-98
        xishaRow3Data: [],
        // 99-147
        xishaRow4Data: []
      },
      xishaDialog: false,
      dongLiMenu: {},
      dongLiItem: {},
      xishaDialog: false,
      showModal: false,
      showDongliModal: false,
      techShow: false,
      data1: {}
    }
  },
  // 组件相互调用 需在beforeCreate注册
  beforeCreate: function() {
    this.$options.components.xishaDialogTech = require('@/views/monitorCenter/workChart/components/qcs/dialogBig/dialog_xisha_tech/index').default
  },
  created() {
    this.dongLiMenu = dongLiMenu
    this.dongLiItem = dongliItem
  },
  components: {
    dongliDialog,
    xisha,
    xishaDialog
  },
  computed: {
    xiShaGroupState() {
      let result
      if (this.$store.state.socketData.length != 0) {
        result = this.$store.state.socketData.filter(item => item.workshop == this.$store.state.workshopNo)
        result = result[0].dsDeviceRealTimeStatusListSpunYarn
      }
      return result
    }
  },
  watch: {
    xiShaGroupState: {
      immediate: true,
      handler(val) {
        if (val) {
          this.xishaData.xishaRow2Data = COMMON.devSnFilter(val, 1, 28)
          this.xishaData.xishaRow3Data = COMMON.devSnFilter(val, 57, 84)
        }
      }
    }
  },
  methods: {
    closeHandle() {
      this.showModal = false
      this.showDongliModal = false
    },
    clickHandle(item) {
      this.data1 = item
      this.data1.classes = this.$store.state.workshopData.shiftSpunYarnTxt
      this.showModal = true
    },
    clickHandleDl(item) {
      console.log('DLitem2', item + '_' + this.$store.state.workshopNo)
      this.showDongliModal = true
      var dialogData = this.dongLiItem[`${item}_${this.$store.state.workshopNo}`]
      this.$nextTick(() => {
        this.$refs.dongliDialog.showDialog(dialogData)
      })
    },
    showDialogTech() {
      this.techShow = true
    },
    closeDialogTech() {
      this.techShow = false
    }
  }
}
</script>

<style lang="less" scoped>
@import '~@/assets/less/workshop.less';
.dongli3_inline {
  position: absolute;
  top: -50px;
}
.dongli4_inline {
  position: absolute;
  transform: translateY(100px);
}
</style>
